Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to count unique learnersin Sensei #2172

Closed
wants to merge 3 commits into from

Conversation

kaitohm
Copy link
Contributor

@kaitohm kaitohm commented Jan 23, 2024

Adds the script provided by @m1r0 in #2111 to wporg-learn plugin

Adds the script provided by @m1r0 in #2111 to wporg-learn plugin
@kaitohm
Copy link
Contributor Author

kaitohm commented Jan 23, 2024

@jonathanbossenger This pull request is ready for a review! 🥳

I'll note, I suppressed a lint error in line 195:

$student_count = $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared

Jonathan and I discussed that this might be permissible in this case.

@kaitohm kaitohm marked this pull request as ready for review January 23, 2024 07:42
@digitalchild digitalchild added [Dev] Needs Review Pull request needing a review. [Component] Learn Plugin Website development issues related to the Learn plugin. labels Jan 25, 2024
Copy link
Collaborator

@jonathanbossenger jonathanbossenger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, just waiting on feedback on that SQL line

wp-content/plugins/wporg-learn/inc/sensei.php Outdated Show resolved Hide resolved
$query .= " AND comment_date_gmt <= '" . $to_date->format( 'Y-m-d H:i:s' ) . "'";
}

$student_count = $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkevan Ben and I discussed this, and we feel ignoring the PHPCS rule here is ok, but we'd appreciate your opinion. I personally can't see how this could be attacked via SQL injection, but maybe I'm missing something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it's true that the current code isn't vulnerable, that doesn't mean in the future it wouldn't be, so it's preferable to built in elements which would force it to not be.

For example, the $from_date variable assignment logic could be changed to grab from the $_GET variable directly or the appended $query concatenation logic changed in a way which did make it.

By adding some prepare statements, it would help avoid those scenarios, particularly when dealing with user input.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkevan Thanks, that's a fair point, I will work on adding sanitization to the date variables, and change the SQL concatenation to use a prepare statement.

@jonathanbossenger
Copy link
Collaborator

@pkevan when you have a moment, @bsanevans and I would appreciate a second pair of eyes on this PR, thanks.

@jonathanbossenger
Copy link
Collaborator

@bsanevans I have merged #2178, so I am going to close this out.

@kaitohm kaitohm deleted the 2111-count-sensei-learners branch February 13, 2024 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Component] Learn Plugin Website development issues related to the Learn plugin. [Dev] Needs Review Pull request needing a review.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants